# Contributor: Jon Ong <jonongjs@rottenmage.com>
# Maintainer: Andy Li <andy@onthewings.net>
pkgname=neko
pkgver=2.3.0
pkgrel=2
pkgdesc="High-level dynamically typed programming language"
url="https://nekovm.org/"
arch="all"
license="LGPL"
depends=""
depends_dev="neko"
makedepends="apache2-dev cmake gc-dev gtk+2.0-dev linux-headers mariadb-connector-c-dev
	mbedtls-dev samurai sqlite-dev"
options=""
install=""
subpackages="$pkgname-dev $pkgname-libs $pkgname-mysql $pkgname-ui
$pkgname-apache2"
source="$pkgname-$pkgver.tar.gz::https://github.com/HaxeFoundation/neko/archive/v${pkgver//./-}.tar.gz
	remove-git-dependent-targets.patch
	"
builddir="$srcdir/$pkgname-${pkgver//./-}"

build() {
	cmake -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=None \
		-DNEKO_JIT_DISABLE=ON \
		-GNinja
	ninja -C build
}

check() {
	ninja -C build test
}

package() {
	DESTDIR="$pkgdir" ninja -C build install
}

_mv_ndll() {
	local _ndlldir="usr/lib/neko"
	mkdir -p "$subpkgdir"/$_ndlldir
	for ndll in "$@"
	do
		mv "$pkgdir"/$_ndlldir/"$ndll".ndll "$subpkgdir"/$_ndlldir
	done
}

mysql() {
	pkgdesc="Neko Virtual Machine - MySQL database support"
	depends=
	_mv_ndll mysql mysql5
}

ui() {
	pkgdesc="Neko Virtual Machine - UI support"
	depends=
	_mv_ndll ui
}

apache2() {
	pkgdesc="Neko Virtual Machine - Apache2 modules"
	depends=
	_mv_ndll mod_neko2 mod_tora2
}

sha512sums="fec51bed0c5500561635656c7456f3da0599aa6a47a25efe739b3c51f9cdded4a8824ed14ab67bab0905d9082cf6f06b3a76c868cb1b61d440957bcd9fd3f3d2  neko-2.3.0.tar.gz
ed1aa657b385df7764b8e3a36edd56e7844ba0d326f79a48ab48f1b88868f3e4529e0e84f0dc9eeaae03e6b00fb2e7253afa10b2d56d677844cdbe9c72b81cc3  remove-git-dependent-targets.patch"
